<?

class TaskUser extends Users{
    
    function GetName(){
        return $this->name.' '.$this->lname;
    }
    
    function GetLink(){
        $html = '';
        $url = Yii::app()->createUrl('/user/show', array('id'=>$this->id));
        if(!empty($this->avatar) and file_exists($_SERVER['DOCUMENT_ROOT'].$this->avatar)){
            $html .= CHtml::link(
                CHtml::image($this->avatar),
                $url,
                array( 'class' => 'userlink__avatar' )
            );
        }
        $html .= CHtml::link(
            $this->name.' '.$this->lname,
            $url,
            array( 'class' => 'userlink__username userlink__role_'.$this->role )
        );
        $html = CHtml::tag('span', array(
            'class' => 'userlink'
        ), $html);
        return $html;
    }
    
    function isManager(){
        return Yii::app()->user->isManager() or Yii::app()->user->isAdmin();
    }
    
    function UserInProject($projectID=false, $userID=false){
        
        $result = false;
        
        $projectID = intval($projectID);
        $userID = intval($userID);
        $userID = $userID <= 0 ? Yii::app()->user->id : $userID;
        
        if(Yii::app()->user->isManager()) $result = true;
        if(Yii::app()->user->isAdmin()) $result = true;
        if(Yii::app()->user->isDeveloper() || Yii::app()->user->isClient()){
            if($projectID > 0 && TaskProjectUser::UserInProject($userID, $projectID))
                $result = true;
        }
        
        return $result;
        
    }
    
}
